/*     */ package com.qmsk.business.bussBill.depositPay.controller;
/*     */ 
/*     */ import com.qmsk.business.bussBill.bussBill.dao.BussBillDao;
/*     */ import com.qmsk.business.bussBill.depositPay.dao.DepositPayDao;
/*     */ import com.qmsk.business.bussBill.pbPaid.PbPaid;
/*     */ import com.qmsk.business.info.integralCash.dao.IntegralCashDao;
/*     */ import com.qmsk.business.info.integralcoupon.dao.IntegralCouponDao;
/*     */ import com.qmsk.business.member.bussbillpaycheck.dao.BussBillPayCheckDao;
/*     */ import com.qmsk.business.member.bussbillpaypos.dao.BussBillPayPosDAO;
/*     */ import com.qmsk.business.member.member.dao.MemberDAO;
/*     */ import com.qmsk.business.member.memberAct.MemberActConst;
/*     */ import com.qmsk.business.member.memberCashCoupBill.dao.MemberCashCouponBillDao;
/*     */ import com.qmsk.business.member.memberCashCoupDetail.dao.MemberCashCouponDetailDAO;
/*     */ import com.qmsk.business.member.memberIntegralBill.dao.MemberIntegralBillDao;
/*     */ import com.qmsk.business.member.memberIntegralDetail.dao.MemberIntegralDetailDAO;
/*     */ import com.qmsk.business.member.memberLog.dao.MemberLogDAO;
/*     */ import com.qmsk.business.member.memberdepositbill.dao.MemberDepositBillDAO;
/*     */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.qmsk.business.store.salebill.params.SaleBillModel;
/*     */ import com.qmsk.business.store.storedRule.dao.StoredRuleDtlDao;
/*     */ import com.qmsk.session.UserSessionInfo;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.http.HttpGsonPtResponseUtils;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.math.BigDecimal;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"depositPay"})
/*     */ public class DepositPayController
/*     */ {
/*  56 */   private static final Logger logger = Logger.getLogger(DepositPayController.class);
/*     */ 
/*     */   @Autowired
/*     */   private MemberLogDAO memberLogDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDAO memberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private ShopMemberDAO shopMemberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private DepositPayDao dao;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillPayCheckDao bussbillpaycheckDao;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillPayPosDAO bussbillPayPosDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDepositBillDAO memberDepositBillDAO;
/*     */ 
/*     */   @Autowired
/*     */   private IntegralCashDao integralCashDao;
/*     */ 
/*     */   @Autowired
/*     */   private IntegralCouponDao integralCouponDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralBillDao memberIntegralBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralDetailDAO integralDetailDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCashCouponBillDao memberCashCouponBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCashCouponDetailDAO memberCashCouponDetailDAO;
/*     */ 
/*     */   @Autowired
/*     */   private StoredRuleDtlDao storedRuleDtlDao;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillDao bussBillDao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 118 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 120 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(shopId, nPageIdx, 
/* 121 */         nPageSize);
/* 122 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 124 */       logger.error(e);
/* 125 */       ResponseUtils.setErrorMsgResponse(
/* 126 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/stId/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListShopIdStId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 136 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 138 */       int stId = 25;
/* 139 */       Map params = new HashMap();
/* 140 */       params.put("shopId", shopId);
/* 141 */       params.put("stId", Integer.valueOf(stId));
/* 142 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopIdStId(params, nPageIdx, 
/* 143 */         nPageSize);
/* 144 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 146 */       logger.error(e);
/* 147 */       ResponseUtils.setErrorMsgResponse(
/* 148 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/stId/cust/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListShopIdStIdCust(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 158 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 160 */       int stId = 25;
/* 161 */       Map params = new HashMap();
/* 162 */       MapUtils.addToMap(params, "shopId", shopId);
/* 163 */       MapUtils.addToMap(params, "stId", Integer.valueOf(stId));
/* 164 */       MapUtils.addToMap(params, "paid", 
/* 165 */         RequestUtils.getInt(request, "paid"));
/* 166 */       MapUtils.addPercentToMap(params, "custName", 
/* 167 */         RequestUtils.getString(request, "custName"));
/* 168 */       MapUtils.addPercentToMap(params, "license", 
/* 169 */         RequestUtils.getString(request, "license"));
/* 170 */       MapUtils.addPercentToMap(params, "billNo", 
/* 171 */         RequestUtils.getString(request, "billNo"));
/* 172 */       MapUtils.addToMap(params, "createTimeStart", 
/* 173 */         RequestUtils.getDate(request, "createTimeStart"));
/* 174 */       MapUtils.addToMap(params, "createTimeEnd", 
/* 175 */         RequestUtils.getDate(request, "createTimeEnd"));
/* 176 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopIdStId(params, nPageIdx, 
/* 177 */         nPageSize);
/* 178 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 180 */       logger.error(e);
/* 181 */       ResponseUtils.setErrorMsgResponse(
/* 182 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListBussId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Integer bussId)
/*     */   {
/*     */     try
/*     */     {
/* 197 */       GsonEbRst gsonEbRst = this.dao.getGsonOfBussId(bussId);
/* 198 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 200 */       logger.error(e);
/* 201 */       ResponseUtils.setErrorMsgResponse(
/* 202 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insertList(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Object shopId)
/*     */   {
/*     */     try
/*     */     {
/* 220 */       int nResult = 0;
/* 221 */       Long id = null;
/* 222 */       String sMaxBillNo = null;
/* 223 */       Long storDtlId = null;
/* 224 */       String storRlName = null;
/* 225 */       ParserDataSetJson p = new ParserDataSetJson(
/* 226 */         request.getParameter("data"));
/* 227 */       if (p != null) {
/* 228 */         if (p.isExistsInsertRows()) {
/* 229 */           for (int i = 0; i < p.getListInsertRows().size(); ++i) {
/* 230 */             GsonHeadOneRow r = (GsonHeadOneRow)p.getListInsertRows().get(i);
/* 231 */             sMaxBillNo = this.memberDepositBillDAO.getMaxBillNo(shopId);
/* 232 */             r.autoAddHeadData("CreateTime", new Date());
/* 233 */             r.autoAddHeadData("BillNo", sMaxBillNo);
/* 234 */             r.autoAddHeadData("CreateUId", 
/* 235 */               UserSessionInfo.getIntUserIdOfRequest(request));
/* 236 */             r.autoAddHeadData("CreateUName", 
/* 237 */               UserSessionInfo.getUserNameOfRequest(request));
/* 238 */             r.autoAddHeadData("stID", 
/* 239 */               Integer.valueOf(PbPaid.getStOfId("depositPay")));
/* 240 */             storDtlId = ObjectComm.objectToLong(
/* 241 */               r.getValueOfName("storedRuledtlId"), Integer.valueOf(0));
/* 242 */             storRlName = (String)r
/* 243 */               .getValueOfName("storedRuleName");
/*     */           }
/*     */         }
/* 246 */         p.delHead(new String[] { "storedRuledtlId", "storedRuleName" });
/* 247 */         nResult = this.dao.applyUpdates(p, "id");
/* 248 */         if ((p.isExistsInsertRows()) && (nResult > 0)) {
/* 249 */           GsonHeadOneRow r = (GsonHeadOneRow)p.getListInsertRows().get(0);
/* 250 */           id = ObjectComm.objectToLong(r.getValueOfName("id"));
/* 251 */           if ((id != null) && (id.longValue() > 0L)) {
/* 252 */             Double deposit = ObjectComm.objectToDouble(
/* 253 */               r.getValueOfName("BillAmt"), Integer.valueOf(0));
/* 254 */             String userName = 
/* 255 */               UserSessionInfo.getUserNameOfRequest(request);
/* 256 */             Long memberId = ObjectComm.objectToLong(
/* 257 */               r.getValueOfName("MemberID"), Integer.valueOf(0));
/* 258 */             String memo = (String)r.getValueOfName("Memo");
/* 259 */             if (memo == null) {
/* 260 */               memo = "depositPayBill";
/*     */             }
/* 262 */             if ((deposit.doubleValue() > 0.0D) && (memberId.longValue() > 0L)) {
/* 263 */               String[] heads = { "MemberID", 
/* 264 */                 "ShopID", "BillNo", "Amount", 
/* 265 */                 "CreateFileTime", "CreateFileMan", 
/* 266 */                 "Status", "BillFrom", "Memo", 
/* 267 */                 "StorRuledtlID", "StorRuleName", "ID" };
/* 268 */               Object[] datas = { memberId, shopId, 
/* 269 */                 sMaxBillNo, deposit, new Date(), userName, 
/* 270 */                 Integer.valueOf(0), "depositPay", memo, 
/* 271 */                 storDtlId, storRlName, id };
/* 272 */               GsonHeadOneRow g = new GsonHeadOneRow(heads, datas);
/* 273 */               nResult = this.memberDepositBillDAO
/* 274 */                 .insertGsonHeadOneRow(g);
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/*     */       ParserDataSetJson pCheck;
/*     */       int i;
/*     */       GsonHeadOneRow r;
/* 281 */       if ((nResult > 0) || (p == null) || (p.isExistsRows())) {
/* 282 */         pCheck = 
/* 283 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "chkPay"));
/* 284 */         if (pCheck != null) {
/* 285 */           if (pCheck.isExistsInsertRows()) {
/* 286 */             for (i = 0; i < pCheck.getListInsertRows().size(); ++i) {
/* 287 */               r = 
/* 288 */                 (GsonHeadOneRow)pCheck.getListInsertRows()
/* 288 */                 .get(i);
/* 289 */               if (id != null) {
/* 290 */                 r.autoAddHeadData("id", id);
/*     */               }
/*     */             }
/*     */           }
/* 294 */           nResult += this.bussbillpaycheckDao.applyUpdates(pCheck);
/*     */         }
/*     */       }
/*     */ 
/* 298 */       if ((nResult > 0) || (p == null) || (p.isExistsRows())) {
/* 299 */         pCheck = 
/* 300 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "posPay"));
/* 301 */         if (pCheck != null) {
/* 302 */           if (pCheck.isExistsInsertRows()) {
/* 303 */             for (i = 0; i < pCheck.getListInsertRows().size(); ++i) {
/* 304 */               r = 
/* 305 */                 (GsonHeadOneRow)pCheck.getListInsertRows()
/* 305 */                 .get(i);
/* 306 */               if (id != null) {
/* 307 */                 r.autoAddHeadData("id", id);
/*     */               }
/*     */             }
/*     */           }
/* 311 */           nResult += this.bussbillPayPosDao.applyUpdates(pCheck);
/*     */         }
/*     */       }
/*     */ 
/* 315 */       if (nResult > 0) {
/* 316 */         DbConnection.commit();
/* 317 */         if (id != null) {
/* 318 */           String[] heads = { "id", "BillNo" };
/* 319 */           Object[] datas = { id, sMaxBillNo };
/* 320 */           ResponseUtils.toGsonEbRst(heads, datas, response);
/* 321 */           return; }
/* 322 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 323 */           RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 324 */           response);
/*     */ 
/* 326 */         return; }
/* 327 */       DbConnection.rollback();
/* 328 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 329 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 330 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 333 */       DbConnection.rollback();
/* 334 */       logger.error(e);
/* 335 */       ResponseUtils.setErrorMsgResponse(
/* 336 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 337 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void editList(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Object shopId)
/*     */   {
/*     */     try
/*     */     {
/* 401 */       int nResult = 0;
/* 402 */       ParserDataSetJson p = new ParserDataSetJson(
/* 403 */         request.getParameter("data"));
/* 404 */       if (p != null) {
/* 405 */         if (p.isExistsUpdateRows()) {
/* 406 */           for (int i = 0; i < p.getListUpdateRows().size(); ++i) {
/* 407 */             GsonHeadOneRow r = (GsonHeadOneRow)p.getListUpdateRows().get(i);
/* 408 */             Long storDtlId = ObjectComm.objectToLong(r
/* 409 */               .getValueOfName("storedRuledtlId"));
/* 410 */             String storRlName = (String)r
/* 411 */               .getValueOfName("storedRuleName");
/* 412 */             Double deposit = ObjectComm.objectToDouble(
/* 413 */               r.getValueOfName("BillAmt"), Integer.valueOf(0));
/* 414 */             String memo = (String)r.getValueOfName("Memo");
/* 415 */             Long id = ObjectComm.objectToLong(r
/* 416 */               .getValueOfName("id"));
/* 417 */             GsonHeadOneRow rr = new GsonHeadOneRow(new String[0], 
/* 418 */               new Object[0]);
/* 419 */             if (storDtlId != null) {
/* 420 */               rr.autoAddHeadData("StorRuledtlID", storDtlId);
/*     */             }
/* 422 */             if (storRlName != null) {
/* 423 */               rr.autoAddHeadData("storedRuleName", storRlName);
/*     */             }
/* 425 */             if (memo != null) {
/* 426 */               rr.autoAddHeadData("memo", memo);
/*     */             }
/* 428 */             if (deposit.doubleValue() > 0.0D) {
/* 429 */               rr.autoAddHeadData("Amount", deposit);
/*     */             }
/* 431 */             if ((rr != null) && (rr.isExistsData())) {
/* 432 */               nResult = this.memberDepositBillDAO.updateJsonOneRow(rr, 
/* 433 */                 id);
/*     */             }
/*     */ 
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 441 */         p.delHead(new String[] { "storedRuledtlId", "storedRuleName" });
/* 442 */         nResult = this.dao.applyUpdatesNo(p);
/*     */       }
/*     */       ParserDataSetJson pCheck;
/* 445 */       if ((nResult > 0) || (p == null) || (p.isExistsRows())) {
/* 446 */         pCheck = 
/* 447 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "chkPay"));
/* 448 */         if (pCheck != null) {
/* 449 */           nResult += this.bussbillpaycheckDao.applyUpdates(pCheck);
/*     */         }
/*     */       }
/*     */ 
/* 453 */       if ((nResult > 0) || (p == null) || (p.isExistsRows())) {
/* 454 */         pCheck = 
/* 455 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "posPay"));
/* 456 */         if (pCheck != null) {
/* 457 */           nResult += this.bussbillPayPosDao.applyUpdates(pCheck);
/*     */         }
/*     */       }
/*     */ 
/* 461 */       if (nResult > 0)
/* 462 */         DbConnection.commit();
/*     */       else {
/* 464 */         DbConnection.rollback();
/*     */       }
/* 466 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 467 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 468 */         response);
/*     */     } catch (Exception e) {
/* 470 */       DbConnection.rollback();
/* 471 */       logger.error(e);
/* 472 */       ResponseUtils.setErrorMsgResponse(
/* 473 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 474 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 490 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 492 */       String[] strParams = id.split(",");
/* 493 */       int nResult = this.dao.deleteParams(strParams);
/* 494 */       nResult += this.bussbillpaycheckDao.deleteOfbussIds(strParams);
/* 495 */       nResult += this.bussbillPayPosDao.deleteOfbussIds(strParams);
/* 496 */       nResult += this.memberDepositBillDAO.deleteParams(strParams);
/* 497 */       if (nResult > 0)
/* 498 */         DbConnection.commit();
/*     */       else {
/* 500 */         DbConnection.rollback();
/*     */       }
/* 502 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 503 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 504 */         response);
/*     */     } catch (Exception e) {
/* 506 */       DbConnection.rollback();
/* 507 */       logger.error(e);
/* 508 */       ResponseUtils.setErrorMsgResponse(
/* 509 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 510 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"check/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void check(HttpServletRequest request, HttpServletResponse response)
/*     */     throws SQLException
/*     */   {
/* 528 */     String id = RequestUtils.getString(request, "id");
/* 529 */     int nResult = 0;
/* 530 */     Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/* 531 */     String userName = UserSessionInfo.getUserNameOfRequest(request);
/*     */     try {
/* 533 */       nResult = this.dao.updateCheckedOfIds(userId, userName, id);
/* 534 */       String billNo = this.dao.getBussBillOfBillNo(id);
/* 535 */       nResult = this.memberDepositBillDAO.updateCheckStatus(userName, billNo);
/* 536 */       if (nResult > 0)
/* 537 */         DbConnection.commit();
/*     */       else {
/* 539 */         DbConnection.rollback();
/*     */       }
/* 541 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 542 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 543 */         response);
/*     */     } catch (Exception e) {
/* 545 */       DbConnection.rollback();
/* 546 */       logger.error(e);
/* 547 */       ResponseUtils.setErrorMsgResponse(
/* 548 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 549 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"paid/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void paidCustId(HttpServletRequest request, @PathVariable("shopId") Long shopId, HttpServletResponse response)
/*     */   {
/* 566 */     String id = RequestUtils.getString(request, "id");
/* 567 */     Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/* 568 */     String userName = UserSessionInfo.getUserNameOfRequest(request);
/* 569 */     int nResult = 0;
/*     */     try {
/* 571 */       nResult = this.dao.updateBillPaidOfIds(id, userId, userName);
/* 572 */       if (nResult > 0)
/* 573 */         DbConnection.commit();
/*     */       else {
/* 575 */         DbConnection.rollback();
/*     */       }
/* 577 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 578 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 579 */         response);
/*     */     } catch (Exception e) {
/* 581 */       DbConnection.rollback();
/* 582 */       logger.error(e);
/* 583 */       ResponseUtils.setErrorMsgResponse(
/* 584 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 585 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"paid/shopId/{shopId}/member"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void paidMember(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 602 */     String id = RequestUtils.getString(request, "id");
/* 603 */     Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/* 604 */     String userName = UserSessionInfo.getUserNameOfRequest(request);
/* 605 */     int nResult = 0;
/*     */     try {
/* 607 */       nResult = this.dao.updateBillPaidOfIds(id, userId, userName);
/* 608 */       if (nResult > 0) {
/* 609 */         nResult = paidDetailOfbsbill(id, userId, userName, response);
/*     */       }
/* 611 */       if (nResult > 0) {
/* 612 */         DbConnection.commit();
/* 613 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 614 */           RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 615 */           response);
/* 616 */         return; }
/* 617 */       DbConnection.rollback();
/* 618 */       PbPaid.getResponse(nResult, response);
/*     */     }
/*     */     catch (Exception e) {
/* 621 */       DbConnection.rollback();
/* 622 */       logger.error(e);
/* 623 */       ResponseUtils.setErrorMsgResponse(
/* 624 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 625 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private int insertSaleBillPaidSavingsNOAW(GsonHeadOneRow r, Double dCach, Object bissId, boolean dpan, String memo, String billNo, Long userId, String userName)
/*     */     throws SQLException
/*     */   {
/* 642 */     int nRstl = 0;
/* 643 */     Integer intAmt = Integer.valueOf(0);
/* 644 */     Double payCahCouPon = Double.valueOf(0.0D);
/* 645 */     Long shopId = (Long)r.getValueOfName("shopId");
/* 646 */     Long memberId = (Long)r.getValueOfName("memberId");
/* 647 */     Integer fixedIntegral = (Integer)r.getValueOfName("FixedIntegral");
/* 648 */     String conSumeType = (String)r.getValueOfName("ConsumeType");
/* 649 */     if (conSumeType.equals("固定积分")) {
/* 650 */       if (dpan)
/* 651 */         intAmt = fixedIntegral;
/*     */       else
/* 653 */         payCahCouPon = Double.valueOf(fixedIntegral.doubleValue());
/*     */     }
/*     */     else {
/* 656 */       Double integralRate = ObjectComm.objectToDouble(
/* 657 */         r.getValueOfName("IntegralRate"), Integer.valueOf(0));
/* 658 */       if (dpan)
/* 659 */         intAmt = getIntegralRatioRslt(integralRate, dCach);
/*     */       else
/* 661 */         payCahCouPon = 
/* 662 */           Double.valueOf(getIntegralRatioRslt(integralRate, dCach)
/* 662 */           .doubleValue());
/*     */     }
/*     */     Long RuleID;
/*     */     String slName;
/*     */     String inFrom;
/*     */     Integer mberVday;
/*     */     Long billId;
/* 665 */     if ((intAmt != null) && (intAmt.intValue() > 0)) {
/* 666 */       RuleID = (Long)r.getValueOfName("RuleID");
/* 667 */       slName = (String)r.getValueOfName("SaleName");
/* 668 */       inFrom = (String)r.getValueOfName("RuleName");
/* 669 */       mberVday = this.memberDAO.getVdayOfmemberId(memberId);
/* 670 */       nRstl = this.memberIntegralBillDao.insertBsBillInAmt(billNo, memberId, 
/* 671 */         shopId, intAmt, RuleID, inFrom, mberVday, slName, bissId, 
/* 672 */         memo);
/* 673 */       billId = this.memberIntegralBillDao.getLastId();
/* 674 */       nRstl = this.integralDetailDAO.insertBusBillDtialInAmt(memberId, shopId, 
/* 675 */         intAmt, mberVday, billId);
/* 676 */       if (nRstl > 0) {
/* 677 */         nRstl = this.memberDAO.updateBillMemberIntAmt(memberId, intAmt);
/* 678 */         nRstl = this.shopMemberDAO.updateBillMemberIntAmt(memberId, intAmt, 
/* 679 */           shopId);
/* 680 */         nRstl = this.bussBillDao.updateBillIdOfAmt(bissId, intAmt);
/* 681 */         this.memberLogDAO.insertBusBillMbLog_IntAmt(MemberActConst.PAID, 
/* 682 */           billNo, intAmt, memberId, userId, userName);
/*     */       } else {
/* 684 */         return -8;
/*     */       }
/*     */     }
/*     */ 
/* 688 */     if ((payCahCouPon != null) && (payCahCouPon.doubleValue() > 0.0D)) {
/* 689 */       RuleID = (Long)r.getValueOfName("RuleID");
/* 690 */       slName = (String)r.getValueOfName("SaleName");
/* 691 */       inFrom = (String)r.getValueOfName("RuleName");
/* 692 */       mberVday = this.memberDAO.getVdayOfmemberId(memberId);
/* 693 */       nRstl = this.memberCashCouponBillDao.insertCashCoupoBill(billNo, 
/* 694 */         memberId, shopId, payCahCouPon, RuleID, inFrom, mberVday, 
/* 695 */         slName, bissId, memo);
/* 696 */       billId = this.memberCashCouponBillDao.getLastId();
/* 697 */       nRstl = this.memberCashCouponDetailDAO.insertCashCoupDtialCash(memberId, 
/* 698 */         shopId, payCahCouPon, mberVday, inFrom, billId);
/* 699 */       if (nRstl > 0) {
/* 700 */         nRstl = this.memberDAO
/* 701 */           .updateBissBillCashConp(memberId, payCahCouPon);
/* 702 */         nRstl = this.shopMemberDAO.updateBissBillCashConp(memberId, 
/* 703 */           payCahCouPon, shopId);
/* 704 */         nRstl = this.bussBillDao.updateBillIdOfCashAmt(bissId, payCahCouPon);
/* 705 */         this.memberLogDAO.insertBusBillMbLog_CashCoup(MemberActConst.PAID, 
/* 706 */           billNo, payCahCouPon, memberId, userId, userName);
/*     */       } else {
/* 708 */         return -7;
/*     */       }
/*     */     }
/* 711 */     return nRstl;
/*     */   }
/*     */ 
/*     */   private Integer getIntegralRatioRslt(Double integralRate, Double dCach)
/*     */   {
/* 716 */     Integer intAmt = Integer.valueOf(0);
/* 717 */     Double rst = Double.valueOf(dCach.doubleValue() * integralRate.doubleValue());
/* 718 */     if (rst.doubleValue() != 0.0D) {
/* 719 */       intAmt = 
/* 720 */         Integer.valueOf(new BigDecimal(String.valueOf(rst)).setScale(0, 
/* 720 */         4).intValue());
/* 721 */       return intAmt;
/*     */     }
/* 723 */     return Integer.valueOf(0);
/*     */   }
/*     */ 
/*     */   private int getGivePresent(Double dDeposit, Long bissId, Long memberId, Long shopId, String memo, Long storRuledtlID, String billNo, Long userId, String userName, Integer stId, SaleBillModel saleBillModel)
/*     */     throws SQLException
/*     */   {
/* 731 */     int nResult = 0;
/* 732 */     GsonHeadOneRow gg = this.integralCashDao.getBillIntegralOfId(memberId, stId, 
/* 733 */       shopId);
/* 734 */     if (gg != null) {
/* 735 */       nResult = insertSaleBillPaidSavingsNOAW(gg, dDeposit, bissId, true, 
/* 736 */         memo, billNo, userId, userName);
/* 737 */       if (nResult < 0) {
/* 738 */         return nResult;
/*     */       }
/*     */     }
/*     */ 
/* 742 */     GsonHeadOneRow qq = this.integralCouponDao.getBillCashCouPonOfId(memberId, 
/* 743 */       stId, shopId);
/* 744 */     if (qq != null)
/*     */     {
/* 746 */       nResult = nResult + 
/* 746 */         insertSaleBillPaidSavingsNOAW(qq, dDeposit, bissId, 
/* 746 */         false, memo, billNo, userId, userName);
/* 747 */       if (nResult < 0) {
/* 748 */         return nResult;
/*     */       }
/*     */     }
/*     */ 
/* 752 */     if ((storRuledtlID != null) && (storRuledtlID.longValue() > 0L)) {
/* 753 */       GsonHeadOneRow dp = this.storedRuleDtlDao
/* 754 */         .getStoredRuleofId(storRuledtlID);
/* 755 */       if (dp != null) {
/* 756 */         Double giveAmt = ObjectComm.objectToDouble(
/* 757 */           dp.getValueOfName("giveAmt"), Integer.valueOf(0));
/* 758 */         Double storedAmt = ObjectComm.objectToDouble(
/* 759 */           dp.getValueOfName("storedAmt"), Integer.valueOf(0));
/* 760 */         Double discount = ObjectComm.objectToDouble(
/* 761 */           dp.getValueOfName("discount"), Integer.valueOf(0));
/* 762 */         if ((discount != null) && (discount.doubleValue() > 0.0D)) {
/* 763 */           saleBillModel.setDiscount(discount);
/*     */         }
/* 765 */         if ((giveAmt.doubleValue() > 0.0D) && (dDeposit.doubleValue() >= storedAmt.doubleValue())) {
/* 766 */           String nBillNo = this.memberDepositBillDAO.getMaxBillNo(shopId);
/* 767 */           int nSlt = this.memberDepositBillDAO.insertBsBillDpst(giveAmt, 
/* 768 */             memberId, nBillNo, shopId, userName, null, "储值赠送", 
/* 769 */             1);
/* 770 */           if (nSlt > 0) {
/* 771 */             saleBillModel.setGiveAmt(giveAmt);
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 776 */     return nResult;
/*     */   }
/*     */ 
/*     */   private int paidDetailOfbsbill(String id, Long userId, String userName, HttpServletResponse response) throws SQLException, Exception
/*     */   {
/* 781 */     Long bissId = Long.valueOf(id);
/* 782 */     int nResult = 0;
/* 783 */     String memo = "";
/* 784 */     GsonHeadOneRow r = this.dao.getGsonHeadOneRowOfBsbillIds(bissId);
/* 785 */     GsonHeadOneRow g = this.memberDepositBillDAO.getDepositOfId(bissId);
/* 786 */     if ((r != null) && (g != null)) {
/* 787 */       Long storRuledtlID = (Long)g.getValueOfName("StorRuledtlID");
/* 788 */       Long shopId = (Long)r.getValueOfName("shopId");
/* 789 */       Long memberId = (Long)r.getValueOfName("memberId");
/* 790 */       String billNo = (String)r.getValueOfName("billNo");
/* 791 */       String memo1 = (String)r.getValueOfName("Memo");
/* 792 */       if (memo1 != null) {
/* 793 */         memo = memo1;
/*     */       }
/* 795 */       Double dDeposit = Double.valueOf(0.0D);
/* 796 */       Double dIntAmt = Double.valueOf(0.0D);
/* 797 */       Double dCach = Double.valueOf(0.0D);
/* 798 */       Double payCashMny = Double.valueOf(0.0D);
/* 799 */       Double payDisctCoup = Double.valueOf(0.0D);
/*     */ 
/* 801 */       if (ObjectComm.objectToDouble(r.getValueOfName("ReceAmt"), Integer.valueOf(0)).doubleValue() == 0.0D) {
/* 802 */         this.memberLogDAO.insertMemberLogBuss(MemberActConst.PAID, billNo, 
/* 803 */           dIntAmt, dDeposit, dCach, dCach, memberId, userId, 
/* 804 */           userName);
/* 805 */         return 1;
/*     */       }
/* 807 */       SaleBillModel saleBillModel = new SaleBillModel();
/* 808 */       Integer stId = ObjectComm.objectToInteger(r.getValueOfName("stID"), 
/* 809 */         Integer.valueOf(0));
/* 810 */       Integer payIntAmt = ObjectComm.objectToInteger(
/* 811 */         r.getValueOfName("PayIntAmt"), Integer.valueOf(0));
/* 812 */       Double payCash = ObjectComm.objectToDouble(
/* 813 */         r.getValueOfName("PayCash"), Integer.valueOf(0));
/* 814 */       Double payDepstAmt = ObjectComm.objectToDouble(
/* 815 */         r.getValueOfName("PayDepstAmt"), Integer.valueOf(0));
/* 816 */       Double payCheck = ObjectComm.objectToDouble(
/* 817 */         r.getValueOfName("PayCheck"), Integer.valueOf(0));
/* 818 */       Double payCredit = ObjectComm.objectToDouble(
/* 819 */         r.getValueOfName("PayCredit"), Integer.valueOf(0));
/* 820 */       if ((payCredit != null) && (payCredit.doubleValue() > 0.0D)) {
/* 821 */         this.memberLogDAO.insertMemberLogBuss(MemberActConst.PAID, billNo, 
/* 822 */           dIntAmt, dDeposit, dCach, dCach, memberId, userId, 
/* 823 */           userName);
/* 824 */         return 1;
/*     */       }
/*     */ 
/* 828 */       Double payPos = ObjectComm.objectToDouble(
/* 829 */         r.getValueOfName("PayPos"), Integer.valueOf(0));
/* 830 */       Double payDisct = ObjectComm.objectToDouble(
/* 831 */         r.getValueOfName("PayDisctCoup"), Integer.valueOf(0));
/* 832 */       Double payCashCoupAmtMny = ObjectComm.objectToDouble(
/* 833 */         r.getValueOfName("PayCashCoupAmt"), Integer.valueOf(0));
/* 834 */       if ((payIntAmt != null) && (payIntAmt.intValue() != 0)) {
/* 835 */         dIntAmt = Double.valueOf(dIntAmt.doubleValue() + payIntAmt.intValue());
/*     */       }
/* 837 */       if ((payDepstAmt != null) && (payDepstAmt.doubleValue() != 0.0D)) {
/* 838 */         dDeposit = Double.valueOf(dDeposit.doubleValue() + payDepstAmt.doubleValue());
/*     */       }
/* 840 */       if ((payCash != null) && (payCash.doubleValue() != 0.0D)) {
/* 841 */         dCach = Double.valueOf(dCach.doubleValue() + payCash.doubleValue());
/*     */       }
/* 843 */       if ((payCheck != null) && (payCheck.doubleValue() != 0.0D)) {
/* 844 */         dCach = Double.valueOf(dCach.doubleValue() + payCheck.doubleValue());
/*     */       }
/*     */ 
/* 852 */       if ((payPos != null) && (payPos.doubleValue() != 0.0D)) {
/* 853 */         dCach = Double.valueOf(dCach.doubleValue() + payPos.doubleValue());
/*     */       }
/* 855 */       if ((payCashCoupAmtMny != null) && (payCashCoupAmtMny.doubleValue() != 0.0D)) {
/* 856 */         payCashMny = Double.valueOf(payCashMny.doubleValue() + payCashCoupAmtMny.doubleValue());
/*     */       }
/* 858 */       if ((payDisct != null) && (payDisct.doubleValue() != 0.0D)) {
/* 859 */         payDisctCoup = Double.valueOf(payDisctCoup.doubleValue() + payDisct.doubleValue());
/*     */       }
/*     */ 
/* 862 */       if (dDeposit.doubleValue() > 0.0D)
/*     */       {
/* 864 */         nResult = nResult + 
/* 864 */           PbPaid.getPositDeposit(dDeposit, memberId, billNo, 
/* 864 */           shopId, bissId, memo);
/* 865 */         if (nResult < 0) {
/* 866 */           return nResult;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 871 */       if (dCach.doubleValue() > 0.0D)
/*     */       {
/* 874 */         nResult = nResult + 
/* 874 */           getGivePresent(dCach, bissId, memberId, shopId, 
/* 873 */           memo, storRuledtlID, billNo, userId, userName, stId, 
/* 874 */           saleBillModel);
/* 875 */         Double giveAmt = saleBillModel.getGiveAmt();
/* 876 */         nResult += this.memberDAO.updateMemberInc(memberId, dCach);
/*     */ 
/* 878 */         nResult = nResult + this.shopMemberDAO
/* 878 */           .updateMemberInc(memberId, dCach, 
/* 878 */           shopId);
/* 879 */         if ((giveAmt != null) && (giveAmt.doubleValue() > 0.0D)) {
/* 880 */           dCach = Double.valueOf(dCach.doubleValue() + giveAmt.doubleValue());
/*     */         }
/* 882 */         nResult += this.memberDAO.updateMbBusBIllDeposit(memberId, dCach);
/*     */ 
/* 884 */         nResult = nResult + this.shopMemberDAO
/* 884 */           .updateMbBusBIllDeposit(memberId, 
/* 884 */           dCach, shopId);
/* 885 */         if (nResult < 0) {
/* 886 */           return nResult;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 932 */       Long outSId = ShopMap.getOutIdOfShopId(shopId);
/* 933 */       Long outMId = this.memberDAO.getOutMIdOfId(memberId);
/* 934 */       if ((outSId != null) && (outMId.longValue() > 0L)) {
/* 935 */         GsonHeadOneRow pa = this.shopMemberDAO.getPaidOneRowOfMemberId(
/* 936 */           memberId, shopId);
/* 937 */         if ((pa != null) && (pa.getDataLength() > 0)) {
/* 938 */           Double discount = saleBillModel.getDiscount();
/* 939 */           if ((discount != null) && (discount.doubleValue() > 0.0D)) {
/* 940 */             pa.autoAddHeadData("discount", discount);
/* 941 */             String[] heads = { "Discount", "ShopID", 
/* 942 */               "MemberID" };
/* 943 */             Object[] datas = { discount, shopId, id };
/* 944 */             GsonHeadOneRow gs = new GsonHeadOneRow(heads, datas);
/* 945 */             this.shopMemberDAO.updateJsonHeadOneRow(gs, 
/* 946 */               "crm_shop_member");
/* 947 */             gs.delHead("ShopID");
/* 948 */             this.memberDAO.updateJsonOneRow(gs);
/*     */           }
/* 950 */           pa.autoAddHeadData("shopId", outSId);
/* 951 */           String nData = "data=" + 
/* 952 */             pa.objectToJsonStr() + "&" + "id" + 
/* 953 */             "=" + outMId;
/* 954 */           String sUrl = "ptmember/editPaid";
/* 955 */           GsonEbRst rst = HttpGsonPtResponseUtils.postPtEbRst(sUrl, 
/* 956 */             nData, response);
/* 957 */           if ((rst == null) || (rst.getState() != 0))
/* 958 */             return -14;
/*     */         }
/*     */         else {
/* 961 */           return -14;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 992 */       this.memberLogDAO
/* 993 */         .insertMemberLogBuss(MemberActConst.PAID, billNo, dIntAmt, 
/* 994 */         dDeposit, dCach, dCach, memberId, userId, userName);
/*     */     }
/* 996 */     return nResult;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.bussBill.depositPay.controller.DepositPayController
 * JD-Core Version:    0.5.3
 */